package genericdemo;
class Food{

}
class Fruit extends Food{

}
class Apple extends Fruit{

}
class Banana extends Fruit{

}
class Test <T>{
    private T val;
    public T getVal(){
        return val;
    }
    public void setVal(T val){
        this.val = val;
    }
}
public class Test1 {
    public static void main(String[] args) {
        Integer a = 200;
        Integer b = 200;
        System.out.println(a==b);
    }



    public static void main4(String[] args) {
        int a = 10;
        Integer integer = a;

        int val = integer;//自动 拆箱->底层调用的还是intValue
        System.out.println(integer);

        int val2 = integer.intValue();//显示 拆箱
        System.out.println(val2);

        double val3 = integer.doubleValue();//显示 拆箱
        System.out.println(val3);
    }

    public static void main3(String[] args) {
        int a = 10;
        Integer integer = a;//自动 装箱->底层调用的还是Interage.valueOf

        Integer integer2 = new Integer(a);//显示 装箱

        Integer ii = Integer.valueOf(a);//显示 装箱

        System.out.println(integer);
        System.out.println(integer2);
        System.out.println(ii);
    }


    public static void main2(String[] args) {
        Test<Fruit> test1 = new Test<>();
        test1.setVal(new Fruit());

        fun2(test1);

        Test<Food> test2 = new Test<>();
        test2.setVal(new Food());

        fun2(test2);
    }
    //通配符的下界，一般用来添加元素
    public static void fun2(Test<? super  Fruit> temp){
        temp.setVal(new Banana());
        temp.setVal(new Apple());
        System.out.println(temp.getVal());
    }




    public static void main1(String[] args) {
        Test<Apple> test1 = new Test<>();
        test1.setVal(new Apple());

        fun(test1);

        Test<Banana> test2 = new Test<>();
        test2.setVal(new Banana());

        fun(test2);
    }
    //通配符的上界，这里只要是Fruit或者Fruit的子类即可
    public static void fun(Test<? extends  Fruit> temp){
        /*
        这里无法确定 temp 引用的是那个子类对象，所以无法进行修改
        temp.setVal(new Banana());
        temp.setVal(new Apple());
    */
        //放的都是Fruit或者Fruit的子类，所以可以直接使用 Fruit 接收
        Fruit banana = temp.getVal();
        System.out.println(temp.getVal());
    }




}
